#!/usr/bin/python
# -*- coding: UTF-8 -*-
#修改左边轴的刻度
import matplotlib.pyplot as plot
import numpy as np
import datetime
import matplotlib.dates as dates


x=np.arange(1,11,1)
y=2*x


def method1():
    plot.plot(x, y)
    ax = plot.gca()
    # ax.locator_params("x",nbins=5)
    # ax.locator_params("y",nbins=5)
    ax.locator_params("both", nbins=5)
    plot.show()


def dateDemo():

    figure=plot.figure()

    start = datetime.datetime(2015, 1, 1)
    end = datetime.datetime(2016, 1, 1)
    delta = datetime.timedelta(days=1)
    date = dates.drange(start, end, delta)
    y = np.random.rand(len(date))
    ax = plot.gca()
    ax.plot_date(date, y, linestyle="-", marker="")
    #格式化
    dataformatter=dates.DateFormatter("%Y-%m")
    ax.xaxis.set_major_formatter(dataformatter)
    #日期自适应
    figure.autofmt_xdate()
    plot.show()
dateDemo()



